#ifndef MACROS_H
#define MACROS_H

#include <string.h>
#include "data.h"

#define READFILE(Var,Type,Ptr) Var = *(Type*)Ptr; Ptr += sizeof(Type);


#define GET(Pos, Tid, Type) (*(Type*)((Pos) + tavm_tables[(Tid)].start))
#define GETE(pDataEntry,Type) (GET((pDataEntry)->pos, (pDataEntry)->tid, Type))
#define READ_CODE(Agent, Type) *(Type*)(Agent->pc + tavm_tables[TID_CODE].start); Agent->pc+=sizeof(Type);
#define OFFSET(Agent,Num) Agent->pc+=Num
#define WRITE(Pos,Tid,Val,Type) ((*(Type*)((Pos)+tavm_tables[(Tid)].start)) = Val)
#define PUT(Pos,Tid,Val,Type) ((*(Type*)((Pos)+tavm_tables[(Tid)].start)) = Val)
#define PUTE(pDataEntry, Val, Type) PUT((pDataEntry)->pos, (pDataEntry)->tid, Val, Type)
//#define READ(SrcPos,Type) (*(Type*)(SrcPos + tavm_file_data))
#define MEMCPY(DestPos,dTid,SrcPos,sTid,Count) memcpy(((t1B*)(DestPos)+tavm_tables[dTid].start),((t1B*)(SrcPos)+tavm_tables[sTid].start),Count)
#define MEMCPYE(DestEntry,SrcEntry,Count) MEMCPY((DestEntry)->pos,(DestEntry)->tid,(SrcEntry)->pos,(SrcEntry)->tid,Count)
#define ISPASSIVE(AgentId) (AgentId >= tavm_active_agents_count ? 1 : 0)

#define sizeofdt(dt) tavm_data_type_size[dt]

struct DataEntry* getDataEntry(pos_t pos);
struct DataEntry* readDataEntry(struct Agent_Var* agent);
pos_t getDataAddr(struct DataEntry* de);
void sendData(struct DataEntry* dest, struct DataEntry* src);
#endif


